GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3f7d3e...63b87e )
by Florian
01:23
created

Marker.setNamePositionRadius   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 9
rs 9.6666
c 2
b 1
f 1
1
/*jslint
2
  indent: 4
3
*/
4
5
/*global
6
  $, Lines, google, Cookies, Coordinates, trackMarker
7
*/
8
9
function id2alpha(id) {
10
    'use strict';
11
12
    if (id >= 0 && id < 26) {
13
        return String.fromCharCode('A'.charCodeAt() + (id % 26));
14
    }
15
    if (id >= 26 && id < 260) {
16
        return String.fromCharCode('A'.charCodeAt() + (id % 26)) +
17
            String.fromCharCode('0'.charCodeAt() + (id / 26));
18
    }
19
20
    return "";
21
}
22
23
24
function alpha2id(alpha) {
25
    'use strict';
26
27
    if (alpha.length < 1 || alpha.length > 2) {
28
        return -1;
29
    }
30
31
    alpha = alpha.toLowerCase();
32
    var letter = 0,
33
        number = 0;
34
35
    if (alpha[0] >= 'a' && alpha[0] <= 'z') {
36
        letter = alpha.charCodeAt(0) - 'a'.charCodeAt(0);
37
    } else {
38
        return -1;
39
    }
40
41
    if (alpha.length === 2) {
42
        if (alpha[1] >= '0' && alpha[1] <= '9') {
43
            number = alpha.charCodeAt(1) - '0'.charCodeAt(0);
44
        } else {
45
            return -1;
46
        }
47
    }
48
49
    return number * 26 + letter;
50
}
51
52
53
/// Marker
54
55
function Marker(parent, id) {
56
    'use strict';
57
58
    this.m_parent = parent;
59
    this.m_id = id;
60
    this.m_alpha = id2alpha(id);
61
    this.m_free = true;
62
    this.m_name = "";
63
    this.m_marker = null;
64
    this.m_circle = null;
65
}
66
67
68
Marker.prototype.toString = function () {
69
    'use strict';
70
71
    return this.getAlpha() + ":" + this.getPosition().lat().toFixed(6) + ":" + this.getPosition().lng().toFixed(6) + ":" + this.getRadius() + ":" + this.getName();
72
};
73
74
75
Marker.prototype.isFree = function () {
76
    'use strict';
77
78
    return this.m_free;
79
};
80
81
82
Marker.prototype.clear = function () {
83
    'use strict';
84
85
    if (this.m_free) {
86
        return;
87
    }
88
89
    this.m_free = true;
90
    this.m_marker.setMap(null);
91
    this.m_marker = null;
92
    this.m_circle.setMap(null);
93
    this.m_circle = null;
94
95
    $('#dyn' + this.m_id).remove();
96
97
    Lines.updateLinesMarkerRemoved(this.m_id);
98
    this.m_parent.handleMarkerCleared();
99
};
100
101
102
Marker.prototype.getId = function () {
103
    'use strict';
104
105
    return this.m_id;
106
};
107
108
109
Marker.prototype.getAlpha = function () {
110
    'use strict';
111
112
    return this.m_alpha;
113
};
114
115
116
Marker.prototype.getName = function () {
117
    'use strict';
118
119
    return this.m_name;
120
};
121
122
123
Marker.prototype.setName = function (name) {
124
    'use strict';
125
126
    this.m_name = name;
127
    this.update();
128
};
129
130
131
Marker.prototype.setPosition = function (position) {
132
    'use strict';
133
134
    this.m_marker.setPosition(position);
135
    this.m_circle.setCenter(position);
136
    this.update();
137
};
138
139
140
Marker.prototype.getPosition = function () {
141
    'use strict';
142
143
    return this.m_marker.getPosition();
144
};
145
146
147
Marker.prototype.setRadius = function (radius) {
148
    'use strict';
149
150
    this.m_circle.setRadius(radius);
151
    this.update();
152
};
153
154
155
Marker.prototype.getRadius = function () {
156
    'use strict';
157
158
    return this.m_circle.getRadius();
159
};
160
161
162
Marker.prototype.setNamePositionRadius = function (name, position, radius) {
163
    'use strict';
164
165
    this.m_name = name;
166
    this.m_marker.setPosition(position);
167
    this.m_circle.setCenter(position);
168
    this.m_circle.setRadius(radius);
169
    this.update();
170
};
171
172
173
Marker.prototype.initialize = function (map, name, position, radius) {
174
    'use strict';
175
176
    this.m_free = false;
177
    this.m_name = name;
178
179
    // marker.png is 26x10 icons (each: 33px x 37px)
180
    var self = this,
181
        iconw = 33,
182
        iconh = 37,
183
        offsetx = (this.m_id % 26) * iconw,
184
        offsety = Math.floor(this.m_id / 26) * iconh,
185
        color = "#0090ff";
186
187
    this.m_marker = new google.maps.Marker({
188
        position: position,
189
        map: map,
190
        icon: new google.maps.MarkerImage(
191
            "img/markers.png",
192
            new google.maps.Size(iconw, iconh),
193
            new google.maps.Point(offsetx, offsety),
194
            new google.maps.Point(0.5 * iconw, iconh - 1)
195
        ),
196
        draggable: true
197
    });
198
199
    google.maps.event.addListener(this.m_marker, "drag", function () { self.update(); });
200
    google.maps.event.addListener(this.m_marker, "dragend", function () { self.update(); });
201
202
    this.m_circle = new google.maps.Circle({
203
        center: position,
204
        map: map,
205
        strokeColor: color,
206
        strokeOpacity: 1,
207
        fillColor: color,
208
        fillOpacity: 0.25,
209
        strokeWeight: 1,
210
        radius: radius
211
    });
212
};
213
214
215
Marker.prototype.update = function () {
216
    'use strict';
217
218
    if (this.m_free) {
219
        return;
220
    }
221
222
    var pos = this.m_marker.getPosition(),
223
        radius = this.m_circle.getRadius();
224
225
    this.m_circle.setCenter(pos);
226
227
    Cookies.set('marker' + this.m_id, pos.lat().toFixed(6) + ":" + pos.lng().toFixed(6) + ":" + radius + ":" + this.m_name, {expires: 30});
228
    $('#view_name' + this.m_alpha).html(this.m_name);
229
    $('#view_coordinates' + this.m_alpha).html(Coordinates.toString(pos));
230
    $('#view_circle' + this.m_alpha).html(radius);
231
    $('#edit_name' + this.m_alpha).val(this.m_name);
232
    $('#edit_coordinates' + this.m_alpha).val(Coordinates.toString(pos));
233
    $('#edit_circle' + this.m_alpha).val(radius);
234
235
    Lines.updateLinesMarkerMoved(this.m_id);
236
};
237
238
239
/// Markers
240
241
var Markers = function () {
242
    'use strict';
243
244
    var id;
245
246
    this.m_markers = new Array(26 * 10);
247
248
    for (id = 0; id !== this.m_markers.length; id = id + 1) {
249
        this.m_markers[id] = new Marker(this, id);
250
    }
251
};
252
253
254
Markers.prototype.getSize = function () {
255
    'use strict';
256
257
    return this.m_markers.length;
258
};
259
260
261
Markers.prototype.getById = function (id) {
262
    'use strict';
263
264
    if (id < 0 || id >= this.m_markers.length) {
265
        return null;
266
    }
267
268
    return this.m_markers[id];
269
};
270
271
272
Markers.prototype.getUsedMarkers = function () {
273
    'use strict';
274
275
    var count = 0;
276
    this.m_markers.map(function (m) {
277
        if (!m.isFree()) {
278
            count = count + 1;
279
        }
280
    });
281
    return count;
282
};
283
284
285
Markers.prototype.getFreeMarkers = function () {
286
    'use strict';
287
288
    return this.getSize() - this.getUsedMarkers();
289
};
290
291
292
Markers.prototype.getFreeId = function () {
293
    'use strict';
294
295
    var id;
296
297
    for (id = 0; id < this.m_markers.length; id = id + 1) {
298
        if (this.m_markers[id].isFree()) {
299
            return id;
300
        }
301
    }
302
    return -1;
303
};
304
305
306
Markers.prototype.getNextUsedId = function (id) {
307
    'use strict';
308
309
    var i;
310
311
    for (i = id + 1; i < this.m_markers.length; i = i + 1) {
312
        if (!this.m_markers[i].isFree()) {
313
            return i;
314
        }
315
    }
316
    return -1;
317
};
318
319
320
Markers.prototype.removeById = function (id) {
321
    'use strict';
322
323
    this.m_markers[id].clear();
324
};
325
326
327
Markers.prototype.deleteAll = function () {
328
    'use strict';
329
330
    this.m_markers.map(
331
        function (m) {
332
            m.clear();
333
        }
334
    );
335
};
336
337
338
Markers.prototype.saveMarkersList = function () {
339
    'use strict';
340
341
    var ids = [];
342
    this.m_markers.map(
343
        function (m) {
344
            if (!m.isFree()) {
345
                ids.push(m.getId());
346
            }
347
        }
348
    );
349
    Cookies.set('markers', ids.join(":"), {expires: 30});
350
};
351
352
353
Markers.prototype.toString = function () {
354
    'use strict';
355
356
    var parts = [];
357
    this.m_markers.map(
358
        function (m) {
359
            if (!m.isFree()) {
360
                parts.push(m.toString());
361
            }
362
        }
363
    );
364
    return parts.join("*");
365
};
366
367
368
Markers.prototype.update = function () {
369
    'use strict';
370
371
    this.m_markers.map(
372
        function (m) {
373
            m.update();
374
        }
375
    );
376
};
377
378
379
Markers.prototype.handleMarkerCleared = function () {
380
    'use strict';
381
382
    if (this.getUsedMarkers() === 0) {
383
        $('#btnmarkers2').hide();
384
    }
385
386
    this.saveMarkersList();
387
};
388
389
390
Markers.prototype.goto = function (id) {
391
    'use strict';
392
393
    trackMarker('goto');
394
395
    var m = this.getById(id);
396
    if (m) {
397
        this.m_map.setCenter(m.getPosition());
398
    }
399
};
400
401
402
Markers.prototype.center = function (id) {
403
    'use strict';
404
405
    trackMarker('center');
406
407
    var m = this.getById(id);
408
    if (m) {
409
        m.setPosition(this.m_map.getCenter());
410
    }
411
};
412